import axios from 'axios';

// 登录请求方法
const loginreq = (method, url, params) => {
  return axios({
    method: method,
    url: url,
    baseURL: process.env.BASE_API, // api 的 base_url
    headers: {
      'Content-Type': 'application/json; charset=utf-8',
    },
    data: params
  }).then(res => res.data);
};
// 通用公用方法
const req = (method, url, params) => {
  return axios({
    method: method,
    url: url,
    baseURL: process.env.BASE_API, // api 的 base_url
    headers: {
      'Content-Type': 'application/json; charset=utf-8',
      token: localStorage.getItem('logintoken')
    },
    data: params
  }).then(res => res.data);
};

// 通用公用方法传Params的req
const reqParams = (method, url, params) => {
  return axios({
    method: method,
    url: url,
    baseURL: process.env.BASE_API, // api 的 base_url
    headers: {
      'Content-Type': 'application/json; charset=utf-8',
      token: localStorage.getItem('logintoken')
    },
    params: params
  }).then(res => res.data);
};

// 通用公用方法传Params的req
const reqUploadParams = (method, url, params) => {
  console.log('文件上传')
  return axios({
    method: method,
    processDate: false,
    url: url,
    baseURL: process.env.BASE_API, // api 的 base_url
    headers: {
      'Content-Type': 'multipart/form-data',
      token: localStorage.getItem('logintoken')
    },
    params: params
  }).then(res => res.data);
};

export {
  loginreq,
  req,
  reqParams,
  reqUploadParams
}
